
ITEM.base = "base_weapon"
ITEM.size = Vector(1,1,0.3)
ITEM.class = "axe"
ITEM.label = "Axe"
ITEM.description = "A primitive axe held together with sap."
ITEM.weight = 6
ITEM.model = "models/props_debris/wood_board02a.mdl"
ITEM.icon = "wintersurvival/icon_axe"

ITEM.holdtype = "melee"
ITEM.viewmodel = {
	{
		bone = "ValveBiped.Bip01_R_Hand",
		model = "models/props_junk/Rock001a.mdl",
		size = Vector(0.1,0.5,1),
		pos = Vector(3,-4,-27),
		ang = Angle(0,0,0),
	},
	{
		bone = "ValveBiped.Bip01_R_Hand",
		model = "models/props_debris/wood_board02a.mdl",
		size = Vector(.5,.5,.5),
		pos = Vector(3,-1.5,-12),
		ang = Angle(0,0,0),
	},
}
ITEM.damage = 60
ITEM.range = 64
ITEM.cooldown = .5

//Weapon

function ITEM:onPrimary(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	
	if CLIENT or not itemtab then
		return
	end
	
	if (itemtab.lastused + self.cooldown) < CurTime() then
		local trace = {}
		trace.start = pl:GetShootPos()
		trace.endpos = pl:GetShootPos() + (pl:GetAimVector() * self.range)
		trace.filter = pl
		local tr = util.TraceLine(trace)
		
		//Play animation
		pl:RestartGesture(pl:Weapon_TranslateActivity(ACT_HL2MP_GESTURE_RANGE_ATTACK))
		
		if tr.Hit then
			if tr.HitNonWorld and IsValid(tr.Entity) then
				local ent = tr.Entity
				local class = ent:GetClass()
				//pl:ChatPrint(ent:GetModel())
				
				//We may have to make sounds emit serverside only
				if SERVER and GM.IsDamageableClass(class) then
					ent:TakeDamage(self.damage,pl)
					
					//Play hit player sound
					pl:EmitSound(Sound("physics/flesh/flesh_impact_hard"..math.random(1,6)..".wav"),100,math.random(90,110))
					
				elseif GM.IsTreeModel(ent:GetModel()) then
					//Play hit tree sound
					if SERVER and math.random(1,35)/10 < 1 then
						pl:WSGive("wood",1)
					end
					pl:EmitSound(Sound("physics/concrete/rock_impact_hard"..math.random(1,6)..".wav"),100,math.random(90,110))
				else
					//Play hit world sound
					pl:EmitSound(Sound("physics/surfaces/sand_impact_bullet"..math.random(1,4)..".wav"),100,math.random(90,110))
				end
			else
				//Play hit world sound
				pl:EmitSound(Sound("physics/surfaces/sand_impact_bullet"..math.random(1,4)..".wav"),100,math.random(90,110))
			end
		else
			//Play swing sound
			pl:EmitSound(Sound("weapons/iceaxe/iceaxe_swing1.wav"),100,math.random(90,110))
		end
		itemtab.lastused = CurTime()
	else
		//We do not call the baseclass's function from the non-respective function (This is onPrimary, not FireAfterCooldown)
		self:FireAfterCooldown(pl)
	end
end

function ITEM:onSecondary(pl)
end

function ITEM:onPrecache()
	for i = 1,6 do
		Sound("physics/concrete/rock_impact_hard"..i..".wav")
		Sound("physics/flesh/flesh_impact_hard"..i..".wav")
	end
	for i = 1,4 do
		Sound("physics/surfaces/sand_impact_bullet"..i..".wav")
	end
	Sound("weapons/iceaxe/iceaxe_swing1.wav")
end